package gov.mogaha.ntis.cmm.mob.adapter;

import gov.mogaha.ntis.cmm.mob.R;
import gov.mogaha.ntis.cmm.mob.dto.CmmMobApvCnDto;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CmmMobApvCnAdapter extends BaseAdapter {
	private final LayoutInflater layoutInflater;
	private final ArrayList<CmmMobApvCnDto> list;
	
	public CmmMobApvCnAdapter(Context context, ArrayList<CmmMobApvCnDto> list) {
		this.layoutInflater = LayoutInflater.from(context);
		this.list = list;
	}
	
	public ArrayList<CmmMobApvCnDto> getList() {
		return list;
	}

	public int getCount() {
		return list.size();
	}

	public Object getItem(int position) {
		return list.get(position);
	}
	
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ViewHolder viewHolder;
		CmmMobApvCnDto tmp = list.get(position);
		
		if (convertView == null) {
			
			viewHolder = new ViewHolder();
			convertView = this.layoutInflater.inflate(R.layout.cmmmobapvcnitemview, null);
			
			viewHolder.upchNm = (TextView) convertView.findViewById(R.id.upch_nm);
			viewHolder.tgtApvNo = (TextView) convertView.findViewById(R.id.tgt_apv_no);
			viewHolder.upchAddr = (TextView) convertView.findViewById(R.id.upch_addr);
			
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		
		viewHolder.upchNm.setText(tmp.mUpchNm);
		viewHolder.tgtApvNo.setText(tmp.mTgtApvNo);
		viewHolder.upchAddr.setText(tmp.mUpchAddr);

		convertView.setTag(viewHolder);
		
		return convertView;
	}
	
	private class ViewHolder {
		TextView upchNm;			// 업소명
		TextView tgtApvNo;		// 인허가번호
		TextView upchAddr;			// 업소주소
	}
}

